var app = new Vue({
    el: '#app',
    data: {
        message: {
            account: '',
            mail: '',
            passworld1: '',
            passworld2: '',
            name: ''
        },
        info: {
            account: false,
            mail: false,
            passworld1: false,
            passworld2: false,
            name: false
        }
    },
    methods: {
        submit: function() {

            var sub = true
            var account = /^[a-zA-Z0-9_-]{4,16}$/; //账号判断
            var mail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
            if (this.message.account == '' || this.message.account == null) {
                window.alert('账号为空')
                sub = false
            } else if (!account.test(this.message.account)) {
                window.alert('账号格式错误')
                sub = false
            }
            if (this.message.passworld1 == '' || this.message.passworld1 == null) {
                window.alert('密码为空')
                sub = false
            } else if (this.message.passworld1.length < 4) {
                window.alert('密码太短')
            } else if (this.message.passworld1 != this.message.passworld1) {
                window.alert('两次输入的密码不同')
                sub = false
            }
            if (this.message.mail == '' || this.message.mail == null) {
                window.alert('邮箱为空')
                sub = false
            } else if (!mail.test(this.message.mail)) {
                window.alert('邮箱格式错误')
                sub = false
            }
            if (this.message.name == '' || this.message.name == null) {
                window.alert('昵称为空')
                sub = false
            }
            if (sub) {
                axios.get("http://47.119.134.71:8080/api/user/insert?user_name=" + this.message.name + "&user_account=" + this.message.account + "&user_password=" + this.message.passworld1)
                    .then(res => {
                        show("注册成功")
                        sleep(1000).then(() => {
                            // 这里写sleep之后需要去做的事情
                            window.location = "index.html"
                        })
                    })
                    .catch(err => {
                        console.error(err);
                    })
            }





        },

    }


})